<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <title>玉灵 QQ:7031633 Email:webrx@126.com</title>
    <meta content="关键字" name="keywords">
    <meta content="简介" name="description">
</head>

<body>
<h1 id="ct"></h1>
<h1 id="st"></h1>
<script>
    let fn = e => e > 9 ? e : '0' + e
    let ft = d => {
        let dd = [d.getFullYear(), fn(d.getMonth() + 1), fn(d.getDate())].join('-')
        let tt = [fn(d.getHours()), fn(d.getMinutes()), fn(d.getSeconds())].join(':')
        return `${dd} ${tt}`
    }
    let ct = document.querySelector('#ct')

    function fct() {
        ct.innerHTML = `客户端：${ft(new Date())}`
    }

    fct()
    setInterval(fct, 1000)

    function sct() {

        //let ajax = new XMLHttpRequest()

        //fetch

        //res.text() res.json()
        fetch("http://localhost:8080/time").then(res => res.text()).then(res => {
            st.innerHTML = `服务器：${res}`
        })

    }

    sct()
    //let st = document.querySelector('#st')
    //setInterval(sct, 1000)


    fetch('/time').then(res => {
        console.log(typeof res)
        console.log(res)
        return res.text()
    }).then(res => {
        console.log(res)
    })

</script>
</body>
</html>
